<template>
	<view>
		<view class="navtit">
			<view class="navitem" v-for="(item,index) in typelist" :key="index" @click="changecondition(index,item)">
				<view>{{item.title}}</view>
				<image v-if="item.is_select==false" :src="item.img"></image>
				<image v-else :src="item.imged"></image>
			</view>
		</view>
		<view style="height: 110rpx;"></view>
		<view class="listbox" v-for="(item,index) in list" :key="index" @click="todetail(item)">
			<view class="leftbox">
				<image :src="item.url"></image>
			</view>
			<view class="rightbox">
				<view class="lineone">
					<view class="namebox">{{item.goods_name}}</view>

				</view>
				<view class="numbox" v-if="item.stock_total">
					<!-- <image src="../../static/fir.png"></image> -->
					<view>库存{{item.stock_total}}</view>
				</view>
				<!-- <view class="specbox">八音盒</view> -->
				<view class="pricebox">{{parseFloat(item.score_price)==0?'':parseFloat(item.score_price)}}
					<text style="font-size: 28rpx;" v-if="parseFloat(item.score_price)!==0">积分+</text>
					￥{{parseFloat(item.goods_price_min)}}
					<text class="line-price">¥{{item.line_price_max}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				typelist: [{
						img: '../../static/xu1.png',
						imged: '../../static/xu2.png',
						title: '价格',
						is_select: false
					},
					{
						img: '../../static/xu1.png',
						imged: '../../static/xu2.png',
						title: '最热',
						is_select: false
					},
					{
						img: '../../static/xu1.png',
						imged: '../../static/xu2.png',
						title: '最新',
						is_select: false
					}
				],
				price_sort: '',
				special_sort: '',
				time_sort: '',
				is_data: true,
				list: [],
				page: 1
			}
		},
		onLoad() {
			this.getlist()
		},
		onReachBottom() {
			this.is_data && this.getlist()
		},
		methods: {
			changecondition(index, item) {
				item.is_select = !item.is_select
				if (index == 0 && item.is_select == true) {
					this.price_sort = 1
					this.special_sort = ''
					this.time_sort = ""
				}
				if (index == 0 && item.is_select == false) {
					this.price_sort = 2
					this.special_sort = ''
					this.time_sort = ""
				}
				if (index == 1 && item.is_select == true) {
					this.special_sort = 1
					this.price_sort = ''
					this.time_sort = ""
				}
				if (index == 1 && item.is_select == false) {
					this.special_sort = 2
					this.price_sort = ''
					this.time_sort = ""
				}
				if (index == 2 && item.is_select == true) {
					this.time_sort = 1
					this.price_sort = ''
					this.special_sort = ""
				}
				if (index == 3 && item.is_select == false) {
					this.time_sort = 2
					this.price_sort = ''
					this.special_sort = ""
				}
				this.page = 1
				this.list = []
				this.getlist()
			},
			getlist() {
				this.$http({
					url: '/api/Wechat/getGoodsByCateId',
					data: {
						cate_id: '',
						price_sort: this.price_sort, //价格1倒序2顺序
						special_sort: this.special_sort, //最热排序1倒序2顺序
						time_sort: this.time_sort, //时间排序1倒序2顺序
						is_special: 1, //是否推荐1是0否
						page: this.page,
						limit: 20
					}
				}).then(res => {
					if (res.data.length) {
						this.list.push(...res.data)
						this.page++
						return
					}
					this.is_data = false
				})
			},
			todetail(item) {
				uni.navigateTo({
					url: '/pageshop/goodsinfo/goodsinfo?id=' + item.id
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.navtit {
		width: 100%;
		height: 84rpx;
		background: #FFFFFF;
		position: fixed;
		top: 0;
		display: flex;
		align-items: center;
		z-index: 9;

		.navitem {
			display: flex;
			align-items: center;
			width: 33.3%;
			justify-content: center;

			image {
				width: 14rpx;
				height: 30rpx;
				margin-left: 12rpx;
			}
		}
	}

	.listbox {
		display: flex;
		align-items: center;
		width: 690rpx;
		padding: 0 30rpx;
		height: 270rpx;
		background: #FFFFFF;
		border-radius: 14rpx;
		justify-content: space-between;

		.leftbox {
			text-align: center;
			width: 232rpx;

			image {
				width: 210rpx;
				height: 210rpx;
			}
		}

		.rightbox {
			width: 438rpx;

			.lineone {
				display: flex;

				.namebox {
					width: 358rpx;
					font-size: 36rpx;
					font-family: Source Han Sans CN-Medium, Source Han Sans CN;
					font-weight: 500;
					color: #222222;
					-webkit-line-clamp: 2;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					overflow: hidden;
					text-overflow: ellipsis;
				}

			}

			.specbox {
				width: 438rpx;
				font-size: 28rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #555555;
				margin: 15rpx 0;
				-webkit-line-clamp: 1;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.numbox {
				// width: 80rpx;
				// text-align: center;
				font-size: 24rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #222222;
				margin-top: 10rpx;

				image {
					width: 28rpx;
					height: 36rpx;
				}
			}

			.pricebox {
				width: 438rpx;
				font-size: 36rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #FF6178;
				-webkit-line-clamp: 1;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				overflow: hidden;
				text-overflow: ellipsis;
				margin-top: 20rpx;
			}
		}
	}

	.line-price {
		text-decoration: line-through;
		color: #666666;
		font-size: 28rpx;
		margin-top: 20rpx;
		margin-left: 10rpx;
	}
</style>